class OrderExamination < ActiveRecord::Base
  belongs_to :examination_type
  belongs_to :patient_data
  belongs_to :user
  belongs_to :checking_user, :foreign_key => "checking_user_id", :class_name => "User"
  belongs_to :executing_user, :foreign_key => "executing_user_id", :class_name => "User"

  # --- Validation --- #
  validates_presence_of :examination_type_id
  validates_presence_of :patient_data_id

  class << self
    HUMANIZED_ATTRIBUTE_KEY_NAMES = {
      "examination_type_id" => "pole nazwa badania",
      "patient_data_id" => "pole pacjent"
    }
    def human_attribute_name(attribute_key_name)
      HUMANIZED_ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
    end
  end

  def status
    if self.is_checked
      "Zatwierdzone"
    else
      if self.has_resoult
        "Nie sprawdzone"
      else
        "Nie wykonane"
      end
    end
  end

  def priorytet
   "#{(ExaminationType.find self.examination_type.id).priorytet}"
  end

  def to_label
    "Zlecenie nr. #{self.id}"
  end

end
